package com.itheima.service;

import com.itheima.dao.QueryDao;
import com.itheima.domain.Customer;
import com.itheima.domain.Linkman;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by Mr.King on 2017/2/28.
 */
@Transactional
public class QueryService {
    private QueryDao dao;
    public void setDao(QueryDao dao) {
        this.dao = dao;
    }

    public List findCustomer(Customer customer){
        return dao.findCustomer(customer);
    }

    public List findLinkman(Linkman linkman) {
        List<Integer> cids = null;
        if (linkman.getCustomer().getCustName() != null && !"".equals(linkman.getCustomer().getCustName())) {
            List<Customer> customer = findCustomer(linkman.getCustomer());
            cids = new ArrayList<Integer>();
            for (Customer c : customer) {
                cids.add(c.getCid());
            }
        }
        return dao.findLinkman(linkman,cids);
    }

    public List countIndustry() {
        return dao.countIndustry();
    }

    public List countSource() {
        return dao.statisticsSource();
    }
}
